<?php


namespace App\Evaluation\Actions\Post;

use App\Extensions\Actions\RowAction;
use App\PatentApply;
use App\PatentAssess;
use Illuminate\Http\Request;

class PatentAssessPost extends RowAction
{
    public $name = '评估意见';

    public function handle(PatentAssess $model, Request $request)
    {
        $file = $request->file('file');
        $model->storeFile($file,'path');
        $model->score = $request->get('score');
        $model->remark = $request->get('remark');
        $model->state = 1;
        $model->save();
        $apply = $model->apply;
        if($apply instanceof PatentApply){
            $apply->syncScore();
        }
        return $this->response()->success('操作完成！')->refresh();
    }

    public function form()
    {
        $mimes = 'png,jpg,jpeg,pdf';
        $this->text('score', '评分')
            ->rules('required|numeric', ['required' => '评分不能为空', 'numeric' => '请输入有效数字']);
        $this->file('file', '评估报告')
            ->rules('required|mimes:' . $mimes, ['required' => '请上传评估报告', 'mimes' => '评估报告类型错误'])
            ->help('类型：' . $mimes);
        $this->textarea('remark', '评估意见')->required()->placeholder('100-200字左右')->default($this->row->remark);
    }

}
